package dbmanager;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException;

import framework.FoodItem;
import framework.Utensil;

public class UtensilManager extends DatabaseObjectManager {
	public static boolean utensilExists(Utensil u) throws SQLException {
		return utensilExists(u.getName());
	}

	public static boolean utensilExists(String name) throws SQLException {
		ResultSet rs = dbm.sendQuery("select * from utensil where name='"
				+ name + "'");
		if (rs.next()) {
			return true;
		} else {
			return false;
		}
	}

	public static boolean addUtensil(Utensil u) throws SQLException {
		return addUtensil(u.getName());
	}

	public static boolean addUtensil(String name) throws SQLException {
		try {
			dbm.sendInsertQuery("insert into utensil(name) values('" + name
					+ "')");
			return true;
		} catch (MySQLIntegrityConstraintViolationException e) {
			return false;
		}
	}
	
	public static void main(String[] args) throws SQLException {
		DatabaseObjectManager.connect();
		System.out.println(addUtensil("can of mace2"));
	}
}
